package com.ass.page.web;


import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.ass.base.web.BaseController;
import com.ass.common.generated.dao.TArticleMapper;
import com.ass.common.generated.model.TArticle;
import com.ass.common.generated.model.TArticleExample;
import com.ass.common.service.CommonService;
import com.ass.common.utils.StringUtil;
import com.ass.page.menu.EnumArticleType;

@Controller
@RequestMapping("/door")
public class PageController extends BaseController {

	@Resource
	private CommonService commonService;
	
	@Resource
	private TArticleMapper tArticleMapper;
	
	@RequestMapping("/i")
	public ModelAndView index(HttpServletRequest request, HttpServletResponse response){
		ModelAndView modelAndView = new ModelAndView("door/index");
		int i = (int)(Math.random()*10+1); //1-10随机数
		modelAndView.addObject("bg_path","image/newadd/bg"+i+".jpg");
		return modelAndView;
		
	}
	
	/**显示文章
	 * 
	 * @param request
	 * @param response
	 * @param articleid
	 * @return
	 */
	@RequestMapping("/a")
	public ModelAndView article(HttpServletRequest request, HttpServletResponse response, @RequestParam("id") String articleid){
		logger.info("show article : "+ articleid);
		ModelAndView modelAndView = new ModelAndView("door/article");

		TArticle article = tArticleMapper.selectByPrimaryKey(new Long(articleid));
		modelAndView.addObject("article",article);
		
		String p = request.getParameter("p");
		String purl = "image/newadd/default.jpg";
		if(StringUtil.isNotEmpty(p))
			purl = "image/newadd/"+p+".jpg";
			
		modelAndView.addObject("purl",purl);
		return modelAndView;
		
	}
	
	//产品中心
	@RequestMapping("/pc")
	public ModelAndView productCenter(HttpServletRequest request, HttpServletResponse response){
		ModelAndView modelAndView = new ModelAndView("door/productcenter");
		TArticleExample example = new TArticleExample();
		example.createCriteria().andTypeEqualTo(EnumArticleType.product.getCode());
		example.setOrderByClause("  position asc ");
		List<TArticle> lst =  tArticleMapper.selectByExample(example);
		modelAndView.addObject("lst",lst);
		return modelAndView;
		
	}
	
	//主营业务
	@RequestMapping("/bi")
	public ModelAndView business(HttpServletRequest request, HttpServletResponse response){
		ModelAndView modelAndView = new ModelAndView("door/business");
		TArticleExample example = new TArticleExample();
		example.createCriteria().andTypeEqualTo(EnumArticleType.business.getCode());
		example.setOrderByClause("  position asc ");
		List<TArticle> lst =  tArticleMapper.selectByExample(example);
		modelAndView.addObject("lst",lst);
		return modelAndView;
		
	}
	
	
	
	//最新咨询
	@RequestMapping("/news")
	public ModelAndView customerService(HttpServletRequest request, HttpServletResponse response){
		ModelAndView modelAndView = new ModelAndView("door/news");
		TArticleExample example = new TArticleExample();
		example.createCriteria().andTypeEqualTo(EnumArticleType.news.getCode());
		example.setOrderByClause("  position asc ");
		List<TArticle> lst =  tArticleMapper.selectByExample(example);
		modelAndView.addObject("lst",lst);
		return modelAndView;
		
	}
	
	
	
	//关于我们
	@RequestMapping("/master")
	public ModelAndView master(HttpServletRequest request, HttpServletResponse response){
		ModelAndView modelAndView = new ModelAndView("door/master");
		return modelAndView;
		
	}
	
	//招聘
	@RequestMapping("/joinus")
	public ModelAndView joinus(HttpServletRequest request, HttpServletResponse response){
		ModelAndView modelAndView = new ModelAndView("door/joinus");
		return modelAndView;
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	public static void main(String[] args) {
		double b = Math.random();
		System.out.println(b);
		double b2 = b*10;
		System.out.println(b2);
		System.out.println((int)(b2));
		
		
		
	}
	
	

}
